
//// Data cleaning 2020 ANES
//// Download 2020 ANES data from ANES website (https://electionstudies.org/data-center/2020-time-series-study/)
//// Import file - make sure to import preserving letter case


/// Survey weight "weight", "weight2"
gen weight = V200010b
gen weight2 = weight
destring weight2, replace
destring weight,replace

/// Age "age"
gen age = V201507x
replace age = . if age == -9
replace age = (age-18)/(80-18)
tab age

/// Hispanic "hisp"
tab V201549x
gen hisp = 0
replace hisp =1 if V201549x == 3

/// Black "black"
tab V201549x
gen black = 0
replace black =1 if V201549x == 2

/// White "white"
tab V201549x
gen white = 0
replace white =1 if V201549x == 1

/// Female "female"
gen female = V201600-1
replace female = 0 if female==-9

/// College degree "college"
gen college = 0
replace college = 1 if V201511x > 3

/// Income level "inc"
gen inc = (V201617x-1)/21
replace inc = . if inc < 0

/// Religion importance "relig"
gen relig = (-V201433+5)/4
replace relig = . if relig > 3

/// Born Again Christian
gen bornagain = 0
replace bornagain = 1 if V201456 == 1

/// Census region "region"
gen region = V203003

/// Rural residence "ruralres"
gen ruralres = 0
replace ruralres = 1 if V202355 == 1
replace ruralres = 1 if V202355 == 2

/// Rural identifier (binary) "rasocid_binary"
gen rasocid_binary = 0
replace rasocid_binary = 1 if V202356 == 3
replace rasocid_binary = 1 if V202356 == 4

/// Rural feeling thermometer "ruralft2" (0-1) or "ftrural" (0-100)
gen ftrural = V202184
replace ftrural = . if ftrural > 101
replace ftrural = . if ft
gen ruralft2 = ftrural/100

/// Rural resentment "rc"
gen rc1 = (V202276x-1)/6
replace rc1 = . if rc1 < 0

gen rc2 = (V202279x-1)/6
replace rc2 = . if rc2 < 0

gen rc3 = (V202282x-1)/6
replace rc3 = . if rc3 < 0

egen rc = rmean(rc1 rc2 rc3)


/// Partisanship "pid"
gen pid = (V201231x-1)/6
replace pid = . if pid < 0

/// Symbolic ideology "ideo"
gen ideo = (V201200-1)/6
replace ideo = . if ideo < 0
replace ideo = . if ideo > 10

/// Political interest "interest"
gen interest = (-V202406+4)/4
replace interest = . if interest > 2

/// Support for government spending more "govspend"
gen govspend = (V201246-1)/6
replace govspend = . if govspend > 1
replace govspend = . if govspend < 0

/// Support decreased immigration levels "immlevel"
gen immlevel = (V202232-1)/4
replace immlevel = . if immlevel < 0

/// Believe climate change is affecting weather/temps "climateaffecting"
gen climateaffecting = (V202332-1)/4
replace climateaffecting = . if climateaffecting < 0

/// Support for abortion access "abortion"
gen abortion = (V201336-1)/3
replace abortion = . if V201336 ==  5
replace abortion = . if abortion < 0

/// Support for greater limits on activity to prevent COVID spread "covidlimst"
gen covidlimst = (-V201393+5)/4
replace covidlimst = . if covidlimst > 3

/// Feeling thermometer for Trump "trumpft"
gen trumpft = V201152
replace trumpft = . if trumpft < 0

/// Feeling thermometer for Black Lives Matter "blmft"
gen blmft = V202174
replace blmft = . if blmft > 100
replace blmft = . if blmft < 0

/// Moral traditionalism "moraltrad2"
gen moraltrad2 = (V202264-1)/4
replace moraltrad2 = . if moraltrad2 < 0

/// Racial resentment "rr"
gen rr1 = (-V202300+5)/4
replace rr1 = . if rr1 > 1
gen rr2 = (V202302-1)/4
replace rr2 = . if rr2 < 0
gen rr3 = (V202301-1)/4
replace rr3 = . if rr3 < 0
gen rr4 = (-V202303+5)/4
replace rr4 = . if rr4 > 1

egen rr = rmean(rr1 rr2 rr3 rr4)

/// Anti-Elitism "anti_elite" !!!!!!!!!!!!! REDO ANALYSES
tab V202304
gen ael1 = (V202304-1)/4
replace ael1 = . if ael1 < 0

tab V202305
gen ael2 = (V202305-1)/4
replace ael2 = . if ael2 < 0

egen anti_elite = rmean(ael1 ael2)


/// pol compromise is selling out
gen aela1 = (-V202409+5)/4
replace aela1 = . if aela1 > 2
tab aela1

/// pol don't care about people
gen aela2 = (-V202410+5)/4
replace aela2 = . if aela2 > 2

/// pol are trustworthy
gen aela3 = (V202411-1)/4
replace aela3 = . if aela3 < 0

/// pols the problem
gen aela4 = (-V202412+5)/4
replace aela4 = . if aela4 > 2

/// strong leader
gen aela5 = (-V202413+5)/4
replace aela5 = . if aela5 > 2

/// People decide not pol
gen aela6 = (-V202415+5)/4
replace aela6 = . if aela6 > 2

/// Pols care about rich and powerful
gen aela7 = (-V202414+5)/4
replace aela7 = . if aela7 > 2


/// Anti-Expertise/Intellectualism "anti_exp"
tab V202308x
gen ai1 = (-V202308x+5)/4
replace ai1 = . if ai1 > 1
tab ai1

gen ai2 = (-V202309+5)/4
replace ai2 = . if ai2 > 1
tab ai2

gen ai3 = (-V202310+5)/4
replace ai3 = . if ai3 > 1

egen anti_exp = rmean(ai1 ai2 ai3)



